//
//  CHSimpleListDataSource.swift
//  CHSimpleUI
//
//  Created by cyptt on 2023/3/31.
//

import UIKit

public class CHSimpleListDataSource: CHBaseTabDataSource,UITableViewDataSource {
   
    override init(identifier: String, successCallBack: dataSourceSuccessBlock? = nil) {
        super.init(identifier: identifier,successCallBack: successCallBack)
    }
    
    
}

public extension CHSimpleListDataSource{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        self.datas.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let listModel:CHSimpleListModel? = self.datas[indexPath.row] as? CHSimpleListModel
        
        
        
        if listModel?.cellType == .ALL {
            self.identifier = "CHSimpleListCellID"
            var cell:CHSimpleListCell? = tableView.dequeueReusableCell(withIdentifier: self.identifier) as? CHSimpleListCell
            if cell == nil {
                cell = CHSimpleListCell.init(style: .default, reuseIdentifier: self.identifier)
            }
            if self.successCallBack != nil{
                self.successCallBack!(cell!,self.datas[indexPath.row],indexPath,tableView)
            }
            return cell!
        } else if listModel?.cellType == .L_Title{
            self.identifier = "CHSimpleListOnlyLeftCellID"
            var cell:CHSimpleList_L_Title_Cell? = tableView.dequeueReusableCell(withIdentifier: self.identifier) as? CHSimpleList_L_Title_Cell
            if cell == nil {
                cell = CHSimpleList_L_Title_Cell.init(style: .default, reuseIdentifier: self.identifier)
            }
            if self.successCallBack != nil{
                self.successCallBack!(cell!,self.datas[indexPath.row],indexPath,tableView)
            }
            return cell!
        } else if listModel?.cellType == .L_ALL{
            self.identifier = "CHSimpleListLeftImgTitleCellID"
            var cell:CHSimpleList_L_ALL_Cell? = tableView.dequeueReusableCell(withIdentifier: self.identifier) as? CHSimpleList_L_ALL_Cell
            if cell == nil {
                cell = CHSimpleList_L_ALL_Cell.init(style: .default, reuseIdentifier: self.identifier)
            }
            if self.successCallBack != nil{
                self.successCallBack!(cell!,self.datas[indexPath.row],indexPath,tableView)
            }
            return cell!
        }else if listModel?.cellType == .L_ALL_R_IMG{
            self.identifier = CHUtils.getClassName(CHSimpleList_L_ALL_R_ImgCell.self) + "ID"
            var cell:CHSimpleList_L_ALL_R_ImgCell? = tableView.dequeueReusableCell(withIdentifier: self.identifier) as? CHSimpleList_L_ALL_R_ImgCell
            if cell == nil {
                cell = CHSimpleList_L_ALL_R_ImgCell.init(style: .default, reuseIdentifier: self.identifier)
            }
            if self.successCallBack != nil{
                self.successCallBack!(cell!,self.datas[indexPath.row],indexPath,tableView)
            }
            return cell!
        }else if listModel?.cellType == .L_ALL_R_ALL{
            self.identifier = CHUtils.getClassName(CHSimpleList_L_ALL_R_ALL_Cell.self) + "ID"
            var cell:CHSimpleList_L_ALL_R_ALL_Cell? = tableView.dequeueReusableCell(withIdentifier: self.identifier) as? CHSimpleList_L_ALL_R_ALL_Cell
            if cell == nil {
                cell = CHSimpleList_L_ALL_R_ALL_Cell.init(style: .default, reuseIdentifier: self.identifier)
            }
            if self.successCallBack != nil{
                self.successCallBack!(cell!,self.datas[indexPath.row],indexPath,tableView)
            }
            return cell!
        }else if listModel?.cellType == .L_ALL_R_Title{
            self.identifier = CHUtils.getClassName(CHSimpleList_L_ALL_R_Title_Cell.self) + "ID"
            var cell:CHSimpleList_L_ALL_R_Title_Cell? = tableView.dequeueReusableCell(withIdentifier: self.identifier) as? CHSimpleList_L_ALL_R_Title_Cell
            if cell == nil {
                cell = CHSimpleList_L_ALL_R_Title_Cell.init(style: .default, reuseIdentifier: self.identifier)
            }
            if self.successCallBack != nil{
                self.successCallBack!(cell!,self.datas[indexPath.row],indexPath,tableView)
            }
            return cell!
        }else if listModel?.cellType == .L_Title_R_ALL{
            self.identifier = CHUtils.getClassName(CHSimpleList_L_Title_R_ALL_Cell.self) + "ID"
            var cell:CHSimpleList_L_Title_R_ALL_Cell? = tableView.dequeueReusableCell(withIdentifier: self.identifier) as? CHSimpleList_L_Title_R_ALL_Cell
            if cell == nil {
                cell = CHSimpleList_L_Title_R_ALL_Cell.init(style: .default, reuseIdentifier: self.identifier)
            }
            if self.successCallBack != nil{
                self.successCallBack!(cell!,self.datas[indexPath.row],indexPath,tableView)
            }
            return cell!
        }else if listModel?.cellType == .L_Title_R_IMG{
            self.identifier = CHUtils.getClassName(CHSimpleList_L_Title_R_IMG_Cell.self) + "ID"
            var cell:CHSimpleList_L_Title_R_IMG_Cell? = tableView.dequeueReusableCell(withIdentifier: self.identifier) as? CHSimpleList_L_Title_R_IMG_Cell
            if cell == nil {
                cell = CHSimpleList_L_Title_R_IMG_Cell.init(style: .default, reuseIdentifier: self.identifier)
            }
            if self.successCallBack != nil{
                self.successCallBack!(cell!,self.datas[indexPath.row],indexPath,tableView)
            }
            return cell!
        }else if listModel?.cellType == .L_Title_R_Title{
            self.identifier = CHUtils.getClassName(CHSimpleList_L_Title_R_Title_Cell.self) + "ID"
            var cell:CHSimpleList_L_Title_R_Title_Cell? = tableView.dequeueReusableCell(withIdentifier: self.identifier) as? CHSimpleList_L_Title_R_Title_Cell
            if cell == nil {
                cell = CHSimpleList_L_Title_R_Title_Cell.init(style: .default, reuseIdentifier: self.identifier)
            }
            if self.successCallBack != nil{
                self.successCallBack!(cell!,self.datas[indexPath.row],indexPath,tableView)
            }
            return cell!
        }else if listModel?.cellType == .L_Title_R_IMG_IMG{
            
            
            self.identifier = CHUtils.getClassName(CHSimpleList_L_Title_R_IMG_IMG_TableViewCell.self) + "ID"
            var cell:CHSimpleList_L_Title_R_IMG_IMG_TableViewCell? = tableView.dequeueReusableCell(withIdentifier: self.identifier) as? CHSimpleList_L_Title_R_IMG_IMG_TableViewCell
            if cell == nil {
                cell = CHSimpleList_L_Title_R_IMG_IMG_TableViewCell.init(style: .default, reuseIdentifier: self.identifier)
            }
            if self.successCallBack != nil{
                self.successCallBack!(cell!,self.datas[indexPath.row],indexPath,tableView)
            }
            return cell!
        }else if listModel?.cellType == .L_ALL_R_Input{
            self.identifier = CHUtils.getClassName(CHSimpleList_L_Title_R_Input_Cell.self) + "ID"
            var cell:CHSimpleList_L_ALL_R_Input_Cell? = tableView.dequeueReusableCell(withIdentifier: self.identifier) as? CHSimpleList_L_ALL_R_Input_Cell
            if cell == nil {
                cell = CHSimpleList_L_ALL_R_Input_Cell.init(style: .default, reuseIdentifier: self.identifier)
            }
            if self.successCallBack != nil{
                self.successCallBack!(cell!,self.datas[indexPath.row],indexPath,tableView)
            }
            return cell!
        }else if listModel?.cellType == .L_Title_R_Input{
            self.identifier = CHUtils.getClassName(CHSimpleList_L_Title_R_Input_Cell.self) + "ID"
            var cell:CHSimpleList_L_Title_R_Input_Cell? = tableView.dequeueReusableCell(withIdentifier: self.identifier) as? CHSimpleList_L_Title_R_Input_Cell
            if cell == nil {
                cell = CHSimpleList_L_Title_R_Input_Cell.init(style: .default, reuseIdentifier: self.identifier)
            }
            if self.successCallBack != nil{
                self.successCallBack!(cell!,self.datas[indexPath.row],indexPath,tableView)
            }
            return cell!
        }else {
            self.identifier = "CHSimpleListOlnyCenterCellID"
            var cell:CHSimpleList_Center_Only_Cell? = tableView.dequeueReusableCell(withIdentifier: self.identifier) as? CHSimpleList_Center_Only_Cell
            if cell == nil {
                cell = CHSimpleList_Center_Only_Cell.init(style: .default, reuseIdentifier: self.identifier)
            }
            if self.successCallBack != nil{
                self.successCallBack!(cell!,self.datas[indexPath.row],indexPath,tableView)
            }
            return cell!
        }
       
        
        
        
    }
}

